package com.crm.controller;

import com.crm.domain.TreeNode;
import com.crm.pojo.Permission;
import com.crm.pojo.User;
import com.crm.service.PermissionService;
import com.crm.service.UserService;
import com.crm.util.TreeNodeBuilder;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/index.do")
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/loadIndexLeftMenu.do")
    @ResponseBody
    public List<TreeNode> loadIndexLeftMenu() {
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        User user = (User) session.getAttribute("USER_SESSION");
        List<TreeNode> treeNodes = userService.selectMenusByUid(user.getId());
        return treeNodes;
    }

    @RequestMapping(value = "toUserManager.do")
    public String toUserManager() {
        return "user/userList";
    }

    @RequestMapping(value = "toUserPage.do")
    public String toUserPage() {
        return "user/userAdd";
    }

    @RequestMapping(value = "/toAssignRole.do")
    public String toAssignRole() {
        return "/user/assignRole";
    }

    @RequestMapping(value = "toRoleManager.do")
    public String toRoleManager() {
        return "role/roleList";
    }

    @RequestMapping(value = "/toAssignRight.do")
    public String toAssignRight() {
        return "/role/assignRight";
    }

    @RequestMapping(value = "toPermissionManager.do")
    public String toPermissionManager() {
        return "permission/permissionList";
    }

    @RequestMapping(value = "/toUserEidtPage.do")
    public String toUserEditPage() {
        return "user/userEdit";
    }

    @RequestMapping(value = "toServiceAddManager.do")
    public String toServiceAddManage() {
        return "service/serviceAdd";
    }

    @RequestMapping(value = "toServiceDistributeManager.do")
    public String toServiceDistributeManager() {
        return "service/serviceDistribute";
    }
    @RequestMapping(value = "toServiceDealManager.do")
    public String toServiceDealManager() {
        return "service/serviceDeal";
    }
    @RequestMapping(value = "toAssignPeople.do")
    public String toAssignPeople() {
        return "service/assignPeople";
    }
    @RequestMapping(value = "toServiceDealEdit.do")
    public String toServiceDealEdit() {
        return "service/serviceDealEdit";
    }

    @RequestMapping(value = "toServiceResponseManager.do")
    public String toServiceResponseManager() {
        return "service/serviceResponse";
    }

    @RequestMapping(value = "toServiceResponseEdit.do")
    public String toServiceResponseEdit() {
        return "service/serviceResponseEdit";
    }

    @RequestMapping(value = "toServiceFileManager.do")
    public String toServiceFileManager() {
        return "service/serviceFile";
    }

    @RequestMapping(value = "toServiceFileEdit.do")
    public String toServiceFileEdit() {
        return "service/serviceFileEdit";
    }

    @RequestMapping(value = "toServiceAnalyse.do")
    public String toServiceAnalyse() {
        return "service/serviceAnalyse";
    }

}
